package org.jeecgframework.core.common.service.impl;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.jeecgframework.core.common.dao.ICommonDao;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.hibernate.qbc.HqlQuery;
import org.jeecgframework.core.common.hibernate.qbc.PageList;
import org.jeecgframework.core.common.model.common.DBTable;
import org.jeecgframework.core.common.model.common.UploadFile;
import org.jeecgframework.core.common.model.json.ComboTree;
import org.jeecgframework.core.common.model.json.ImportFile;
import org.jeecgframework.core.common.model.json.TreeGrid;
import org.jeecgframework.core.common.service.CommonService;
import org.jeecgframework.core.util.DateUtils;
import org.jeecgframework.core.util.ReflectUtils;
import org.jeecgframework.tag.vo.datatable.DataTableReturn;
import org.jeecgframework.tag.vo.easyui.Autocomplete;
import org.jeecgframework.tag.vo.easyui.ComboTreeModel;
import org.jeecgframework.tag.vo.easyui.TreeGridModel;
import org.jeecgframework.web.system.pojo.base.TSDepart;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("commonService")
@Transactional
public class CommonServiceImpl implements CommonService {
	public ICommonDao commonDao = null;

	/**
	 * 获取所有数据库表
	 * 
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public List<DBTable> getAllDbTableName() {
		return commonDao.getAllDbTableName();
	}

	@Override
	@Transactional(readOnly = true)
	public Integer getAllDbTableSize() {
		return commonDao.getAllDbTableSize();
	}

	@Resource
	public void setCommonDao(ICommonDao commonDao) {
		this.commonDao = commonDao;
	}

	@Override
	public <T> Serializable save(T entity) {
		return commonDao.save(entity);
	}

	@Override
	public <T> void saveOrUpdate(T entity) {
		commonDao.saveOrUpdate(entity);

	}

	@Override
	public <T> void delete(T entity) {
		commonDao.delete(entity);

	}

	/**
	 * 删除实体集合
	 * 
	 * @param <T>
	 * @param entities
	 */
	@Override
	public <T> void deleteAllEntitie(Collection<T> entities) {
		commonDao.deleteAllEntitie(entities);
	}

	/**
	 * 根据实体名获取对象
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> T get(Class<T> class1, Serializable id) {
		return commonDao.get(class1, id);
	}

	/**
	 * 根据实体名返回全部对象
	 * 
	 * @param <T>
	 * @param hql
	 * @param size
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> List<T> getList(Class clas) {
		return commonDao.loadAll(clas);
	}

	/**
	 * 根据实体名获取对象
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> T getEntity(Class entityName, Serializable id) {
		return commonDao.getEntity(entityName, id);
	}

	/**
	 * 根据实体名称和字段名称和字段值获取唯一记录
	 * 
	 * @param <T>
	 * @param entityClass
	 * @param propertyName
	 * @param value
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> T findUniqueByProperty(Class<T> entityClass, String propertyName, Object value) {
		return commonDao.findUniqueByProperty(entityClass, propertyName, value);
	}

	/**
	 * 按属性查找对象列表.
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> List<T> findByProperty(Class<T> entityClass, String propertyName, Object value) {

		return commonDao.findByProperty(entityClass, propertyName, value);
	}

	/**
	 * 加载全部实体
	 * 
	 * @param <T>
	 * @param entityClass
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> List<T> loadAll(final Class<T> entityClass) {
		return commonDao.loadAll(entityClass);
	}

	@Override
	@Transactional(readOnly = true)
	public <T> T singleResult(String hql) {
		return commonDao.singleResult(hql);
	}

	/**
	 * 删除实体主键ID删除对象
	 * 
	 * @param <T>
	 * @param entities
	 */
	@Override
	public <T> void deleteEntityById(Class entityName, Serializable id) {
		commonDao.deleteEntityById(entityName, id);
	}

	/**
	 * 更新指定的实体
	 * 
	 * @param <T>
	 * @param pojo
	 */
	@Override
	public <T> void updateEntitie(T pojo) {
		commonDao.updateEntitie(pojo);

	}

	/**
	 * 通过hql 查询语句查找对象
	 * 
	 * @param <T>
	 * @param query
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> List<T> findByQueryString(String hql) {
		return commonDao.findByQueryString(hql);
	}

	/**
	 * 根据sql更新
	 * 
	 * @param query
	 * @return
	 */
	@Override
	public int updateBySqlString(String sql) {
		return commonDao.updateBySqlString(sql);
	}

	/**
	 * 根据sql查找List
	 * 
	 * @param <T>
	 * @param query
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> List<T> findListbySql(String query) {
		return commonDao.findListbySql(query);
	}

	/**
	 * 通过属性称获取实体带排序
	 * 
	 * @param <T>
	 * @param clas
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> List<T> findByPropertyisOrder(Class<T> entityClass, String propertyName, Object value, boolean isAsc) {
		return commonDao.findByPropertyisOrder(entityClass, propertyName, value, isAsc);
	}

	/**
	 * 
	 * cq方式分页
	 * 
	 * @param cq
	 * @param isOffset
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public PageList getPageList(final CriteriaQuery cq, final boolean isOffset) {
		return commonDao.getPageList(cq, isOffset);
	}

	/**
	 * 返回DataTableReturn模型
	 * 
	 * @param cq
	 * @param isOffset
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public DataTableReturn getDataTableReturn(final CriteriaQuery cq, final boolean isOffset) {
		return commonDao.getDataTableReturn(cq, isOffset);
	}

	/**
	 * 返回easyui datagrid模型
	 * 
	 * @param cq
	 * @param isOffset
	 * @return
	 */

	@Override
	@Transactional(readOnly = true)
	public void getDataGridReturn(final CriteriaQuery cq, final boolean isOffset) {
		commonDao.getDataGridReturn(cq, isOffset);

	}

	/**
	 * 
	 * hqlQuery方式分页
	 * 
	 * @param cq
	 * @param isOffset
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public PageList getPageList(final HqlQuery hqlQuery, final boolean needParameter) {
		return commonDao.getPageList(hqlQuery, needParameter);
	}

	/**
	 * 
	 * sqlQuery方式分页
	 * 
	 * @param cq
	 * @param isOffset
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public PageList getPageListBySql(final HqlQuery hqlQuery, final boolean isToEntity) {
		return commonDao.getPageListBySql(hqlQuery, isToEntity);
	}

	@Override
	public Session getSession()

	{
		return commonDao.getSession();
	}

	@Override
	@Transactional(readOnly = true)
	public List findByExample(final String entityName, final Object exampleEntity) {
		return commonDao.findByExample(entityName, exampleEntity);
	}

	/**
	 * 通过cq获取全部实体
	 * 
	 * @param <T>
	 * @param cq
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> List<T> getListByCriteriaQuery(final CriteriaQuery cq, Boolean ispage) {
		return commonDao.getListByCriteriaQuery(cq, ispage);
	}

	/**
	 * 文件上传
	 * 
	 * @param request
	 */
	@Override
	public <T> T uploadFile(UploadFile uploadFile) {
		return commonDao.uploadFile(uploadFile);
	}

	@Override
	@Transactional(readOnly = true)
	public HttpServletResponse viewOrDownloadFile(UploadFile uploadFile)

	{
		return commonDao.viewOrDownloadFile(uploadFile);
	}

	/**
	 * 生成XML文件
	 * 
	 * @param fileName
	 *            XML全路径
	 * @return
	 */
	@Override
	public HttpServletResponse createXml(ImportFile importFile) {
		return commonDao.createXml(importFile);
	}

	/**
	 * 解析XML文件
	 * 
	 * @param fileName
	 *            XML全路径
	 */
	@Override
	public void parserXml(String fileName) {
		commonDao.parserXml(fileName);
	}

	@Override
	@Transactional(readOnly = true)
	public List<ComboTree> comTree(List<TSDepart> all, ComboTree comboTree) {
		return commonDao.comTree(all, comboTree);
	}

	@Override
	@Transactional(readOnly = true)
	public List<ComboTree> ComboTree(List all, ComboTreeModel comboTreeModel, List in, boolean recursive) {
		return commonDao.ComboTree(all, comboTreeModel, in, recursive);
	}

	/**
	 * 构建树形数据表
	 */
	@Override
	@Transactional(readOnly = true)
	public List<TreeGrid> treegrid(List all, TreeGridModel treeGridModel) {
		return commonDao.treegrid(all, treeGridModel);
	}

	/**
	 * 获取自动完成列表
	 * 
	 * @param <T>
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> List<T> getAutoList(Autocomplete autocomplete) {
		StringBuffer sb = new StringBuffer("");
		for (String searchField : autocomplete.getSearchField().split(",")) {
			sb.append("  or " + searchField + " like '%" + autocomplete.getTrem() + "%' ");
		}
		String hql = "from " + autocomplete.getEntityName() + " where 1!=1 " + sb.toString();
		return commonDao.getSession().createQuery(hql).setFirstResult(autocomplete.getCurPage() - 1)
				.setMaxResults(autocomplete.getMaxRows()).list();
	}

	@Override
	public Integer executeSql(String sql, List<Object> param) {
		return commonDao.executeSql(sql, param);
	}

	@Override
	public Integer executeSql(String sql, Object... param) {
		return commonDao.executeSql(sql, param);
	}

	@Override
	public Integer executeSql(String sql, Map<String, Object> param) {
		return commonDao.executeSql(sql, param);
	}

	@Override
	public Object executeSqlReturnKey(String sql, Map<String, Object> param) {
		return commonDao.executeSqlReturnKey(sql, param);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Map<String, Object>> findForJdbc(String sql, int page, int rows) {
		return commonDao.findForJdbc(sql, page, rows);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Map<String, Object>> findForJdbc(String sql, Object... objs) {
		return commonDao.findForJdbc(sql, objs);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Map<String, Object>> findForJdbcParam(String sql, int page, int rows, Object... objs) {
		return commonDao.findForJdbcParam(sql, page, rows, objs);
	}

	@Override
	@Transactional(readOnly = true)
	public <T> List<T> findObjForJdbc(String sql, int page, int rows, Class<T> clazz) {
		return commonDao.findObjForJdbc(sql, page, rows, clazz);
	}

	@Override
	@Transactional(readOnly = true)
	public Map<String, Object> findOneForJdbc(String sql, Object... objs) {
		return commonDao.findOneForJdbc(sql, objs);
	}

	@Override
	@Transactional(readOnly = true)
	public Long getCountForJdbc(String sql) {
		return commonDao.getCountForJdbc(sql);
	}

	@Override
	@Transactional(readOnly = true)
	public Long getCountForJdbcParam(String sql, Object... objs) {
		return commonDao.getCountForJdbcParam(sql, objs);
	}

	@Override
	public <T> void batchSave(List<T> entitys) {
		this.commonDao.batchSave(entitys);
	}

	/**
	 * 通过hql 查询语句查找对象
	 * 
	 * @param <T>
	 * @param query
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public <T> List<T> findHql(String hql, Object... param) {
		return this.commonDao.findHql(hql, param);
	}

	@Override
	@Transactional(readOnly = true)
	public <T> List<T> pageList(DetachedCriteria dc, int firstResult, int maxResult) {
		return this.commonDao.pageList(dc, firstResult, maxResult);
	}

	@Override
	@Transactional(readOnly = true)
	public <T> List<T> findByDetached(DetachedCriteria dc) {
		return this.commonDao.findByDetached(dc);
	}

	/**
	 * 调用存储过程
	 */
	@Override
	public <T> List<T> executeProcedure(String procedureSql, Object... params) {
		return this.commonDao.executeProcedure(procedureSql, params);
	}

	@Override
	public <T> List<T> queryPreEntrylist(Class<T> entityClass, String pre, String where, Object... params) {
		// TODO Auto-generated method stub
		Map<String, String> table = ReflectUtils.getTableName(entityClass);
		String tableName = table.get("tableName");
		Map<String, String> columns = ReflectUtils.getColumnName(entityClass);
		Set<String> set = columns.keySet();
		// 转换所有查询的字段
		String columnstrs = getColumnstrsbySet(columns, set);
		// columns.get("column");
		List<Object[]> ls = null;
		if (where != null) {
			ls = this.commonDao.executeProcedure(
					"select " + columnstrs + " from " + pre + "_" + tableName + " where " + where, params);
		} else {
			String s[] = { "0" };
			ls = this.commonDao
					.executeProcedure("select " + columnstrs + " from " + pre + "_" + tableName + " where 0=?", s);
		}
		// 转换成list的实体
		List<T> listobj = ConversionToListEntry(entityClass, set, ls);
		return listobj;

	}

	private <T> List<T> ConversionToListEntry(Class<T> entityClass, Set<String> set, List<Object[]> ls) {
		List<T> listobj = new ArrayList<T>();
		for (Object[] objs : ls) {
			T obj = null;
			try {
				obj = entityClass.newInstance();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			int i = 0;
			Map<String, Class<?>> maptype = ReflectUtils.getClassPropertyType(entityClass);
			for (String column : set) {

				ReflectUtils.setValue(obj, entityClass, column, maptype.get(column), objs[i]);
				i = i + 1;
			}
			listobj.add(obj);
		}
		return listobj;
	}

	private <T> List<T> ConversionToListEntry1(Class<T> entityClass, Set<String> set, List<Map<String, Object>> ls) {
		List<T> listobj = new ArrayList<T>();
		for (Map<String, Object> objs : ls) {
			T obj = null;
			try {
				obj = entityClass.newInstance();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			int i = 0;
			Map<String, Class<?>> maptype = ReflectUtils.getClassPropertyType(entityClass);
			for (String column : set) {

				ReflectUtils.setValue(obj, entityClass, column, maptype.get(column), objs.get(column));
				i = i + 1;
			}
			listobj.add(obj);
		}
		return listobj;
	}

	private String getColumnstrsbySet(Map<String, String> columns, Set<String> set) {
		String columnstrs = "";
		for (String column : set) {
			columnstrs = columnstrs + "," + columns.get(column);
		}
		columnstrs = columnstrs.replaceFirst(",", "");
		return columnstrs;
	}

	@Override
	@Transactional(readOnly = true)
	public <T> List<T> queryPreEntrylistForJdbcParam(Class<T> entityClass, String pre, T entity, int page, int rows) {
		// TODO Auto-generated method stub
		Map<String, String> table = ReflectUtils.getTableName(entityClass);
		String tableName = table.get("tableName");
		Map<String, String> columns = ReflectUtils.getColumnName(entityClass);
		Set<String> set = columns.keySet();
		// 转换所有查询的字段
		String columnstrs = getColumnstrsbySet(columns, set);
		// columns.get("column");
		List<Map<String, Object>> ls = null;
		String where = "";
		List<Object> lsobj = new ArrayList<Object>();
		// 组装查询条件，只能and查询
		SimpleDateFormat SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		for (String column : set) {
			Object updatevalue = ReflectUtils.getPkValueByName(entity, column);
			if (updatevalue != null && !updatevalue.toString().trim().equals("")) {
				if (updatevalue instanceof java.util.Date) {
					updatevalue = DateUtils.date2Str((java.util.Date) updatevalue, SimpleDateFormat);
				} else if (updatevalue instanceof java.sql.Date) {
					updatevalue = DateUtils.date2Str((java.sql.Date) updatevalue, SimpleDateFormat);
				}
				where = where + column + "=? and ";
				lsobj.add(updatevalue);
			}

		}
		if (where.lastIndexOf("and") > 0) {
			where = where.substring(0, where.lastIndexOf("and"));
		}

		Object objs[] = lsobj.toArray(new Object[lsobj.size()]);
		if (!where.equals("")) {
			ls = commonDao.findForJdbcParam(
					"select " + columnstrs + " from " + pre + "_" + tableName + " where " + where, page, rows, objs);

		} else {
			String s[] = { "0" };
			ls = this.commonDao.findForJdbcParam(
					"select " + columnstrs + " from " + pre + "_" + tableName + " where 0=?", page, rows, s);
		}
		// 转换成list的实体
		List<T> listobj = ConversionToListEntry1(entityClass, set, ls);
		return listobj;

	}

	@Override
	@Transactional(readOnly = true)
	public <T> int queryCountForJdbcParam(Class<T> entityClass, String pre, T entity) {
		// TODO Auto-generated method stub
		Map<String, String> table = ReflectUtils.getTableName(entityClass);
		String tableName = table.get("tableName");
		Map<String, String> columns = ReflectUtils.getColumnName(entityClass);
		Set<String> set = columns.keySet();
		// 转换所有查询的字段
		String columnstrs = getColumnstrsbySet(columns, set);
		// columns.get("column");
		List<String> ls = null;
		String where = "";
		List<Object> lsobj = new ArrayList<Object>();
		Field id = null;
		try {
			id = ReflectUtils.getIdField(entity.getClass());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 组装查询条件，只能and查询
		SimpleDateFormat SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		for (String column : set) {
			Object updatevalue = ReflectUtils.getPkValueByName(entity, column);
			if (updatevalue != null && !updatevalue.toString().trim().equals("")) {
				if (updatevalue instanceof java.util.Date) {
					updatevalue = DateUtils.date2Str((java.util.Date) updatevalue, SimpleDateFormat);
				} else if (updatevalue instanceof java.sql.Date) {
					updatevalue = DateUtils.date2Str((java.sql.Date) updatevalue, SimpleDateFormat);
				}
				where = where + column + "=? and ";
				lsobj.add(updatevalue);
			}

		}
		if (where.lastIndexOf("and") > 0) {
			where = where.substring(0, where.lastIndexOf("and"));
		}

		Object objs[] = lsobj.toArray(new Object[lsobj.size()]);
		if (!where.equals("")) {
			ls = commonDao.executeProcedure(
					"select count(" + id.getName() + ")" + " from " + pre + "_" + tableName + " where " + where, objs);

		} else {
			String s[] = { "0" };
			ls = this.commonDao.executeProcedure(
					"select count(" + id.getName() + ")" + " from " + pre + "_" + tableName + " where 0=?", s);
		}
		// 转换成list的实体
		return Integer.valueOf(String.valueOf(ls.get(0)));

	}

	@Override
	public <T> int saveorupdatePreEntry(T entity, String pre) {
		// 采用全量更新
		// 获取主键
		Field id = null;
		try {
			id = ReflectUtils.getIdField(entity.getClass());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Object idval = ReflectUtils.getPkValueByName(entity, id.getName());
		Map<String, String> table = ReflectUtils.getTableName(entity.getClass());
		String tableName = table.get("tableName");
		Map<String, String> columns = ReflectUtils.getColumnName(entity.getClass());
		Set<String> set = columns.keySet();
		SimpleDateFormat SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if (idval != null) {
			// 更新
			String sql = "update " + pre + "_" + tableName + " set ";
			for (String column : set) {
				Object updatevalue = ReflectUtils.getPkValueByName(entity, column);
				if (updatevalue instanceof java.util.Date) {
					updatevalue = DateUtils.date2Str((java.util.Date) updatevalue, SimpleDateFormat);
				} else if (updatevalue instanceof java.sql.Date) {
					updatevalue = DateUtils.date2Str((java.sql.Date) updatevalue, SimpleDateFormat);
				}

				sql = sql + column + "='" + updatevalue + "',";
			}
			sql = sql.substring(0, sql.lastIndexOf(","));
			sql = sql + " where " + id.getName() + "=" + idval;
			return commonDao.updateBySqlString(sql);
		} else {
			// 新增
			String sql = "INSERT INTO " + pre + "_" + tableName + " (";
			for (String column : set) {
				// 去除主键。主键自动递增
				if (!column.equals(id.getName())) {
					sql = sql + column + ",";
				}

			}
			sql = sql.substring(0, sql.lastIndexOf(","));
			sql = sql + ") values (";
			for (String column : set) {
				// 去除主键。主键自动递增
				if (!column.equals(id.getName())) {
					Object updatevalue = ReflectUtils.getPkValueByName(entity, column);
					if (updatevalue instanceof java.util.Date) {
						updatevalue = DateUtils.date2Str((java.util.Date) updatevalue, SimpleDateFormat);
					} else if (updatevalue instanceof java.sql.Date) {
						updatevalue = DateUtils.date2Str((java.sql.Date) updatevalue, SimpleDateFormat);
					}
					sql = sql + "'" + updatevalue + "',";
				}

			}
			sql = sql.substring(0, sql.lastIndexOf(","));
			sql = sql + ")";
			return commonDao.updateBySqlString(sql);
		}

		// return 1;
		// return commonDao.updateBySqlString(sql);
	}

	@Override
	public <T> int deletebyBatch(Class<T> entity, String pre, String[] ids) {
		// 采用全量更新
		// 获取主键
		Field id = null;
		try {
			id = ReflectUtils.getIdField(entity);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Object idval = ReflectUtils.getPkValueByName(entity, id.getName());
		Map<String, String> table = ReflectUtils.getTableName(entity);
		String tableName = table.get("tableName");
		Map<String, String> columns = ReflectUtils.getColumnName(entity);
		Set<String> set = columns.keySet();
		SimpleDateFormat SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if (ids != null && ids.length > 0) {
			for (String objid : ids) {
				String delstr = "DELETE from " + pre + "_" + tableName + " where " + id.getName() + "=?";
				commonDao.executeSql(delstr, objid);
			}
			return 1;

		} else {
			return 0;
		}
	}

	@Override
	public <T> List<T> getList(Class clas, String pre) {
		// TODO Auto-generated method stub
		Map<String, String> table = ReflectUtils.getTableName(clas);
		String tableName = table.get("tableName");
		Map<String, String> columns = ReflectUtils.getColumnName(clas);
		Set<String> set = columns.keySet();
		// 转换所有查询的字段
		String columnstrs = getColumnstrsbySet(columns, set);
		// columns.get("column");
		List<Object[]> ls = null;

		ls = this.commonDao.executeProcedure("select " + columnstrs + " from " + pre + "_" + tableName);

		// 转换成list的实体
		List<T> listobj = ConversionToListEntry(clas, set, ls);
		return listobj;
	}

}
